package visiopuce.DAO;

import java.math.BigDecimal;

import org.hibernate.Query;

import visiopuce.HibernateUtil;
import visiopuce.objets.Biomedecine;

public class BiomedecineDAOImpl extends GenericDAOImpl<Biomedecine, BigDecimal> implements BiomedecineDAO {

	/** Constructeur priv� */
	private BiomedecineDAOImpl() {
	}

	/** Instance unique non pr�initialis�e */
	private static BiomedecineDAOImpl INSTANCE = null;

	/** Point d'acc�s pour l'instance unique du singleton */
	public static BiomedecineDAO getInstance() {
		if (INSTANCE == null) {
			INSTANCE = new BiomedecineDAOImpl();
		}
		return INSTANCE;
	}

	@Override
	public Biomedecine getBiomedecineByLibelle(String libelle) {
		String sql = "SELECT r FROM Biomedecine r WHERE r.libelle like :libelle";
		Query query = HibernateUtil.getSession().createQuery(sql);
		query.setParameter("libelle", libelle);
		return findOne(query);
	}

	@Override
	public Biomedecine getTypeIndicationByLibelleAndCategorie(String biomed, int catbiomed) {
		String sql = "SELECT r FROM Biomedecine r WHERE r.libelle like :libelle and r.categorie = :cat";
		Query query = HibernateUtil.getSession().createQuery(sql);
		query.setParameter("libelle",  biomed + "%");
		query.setParameter("cat",  catbiomed);
		return findOne(query);
	}
}